package it.antonio.leaves.testrepository;

import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl implements UserService{

        private List<User> users = new ArrayList<User>();
        
        private UserDao userDao;
        
        public UserServiceImpl(UserDao userDao) {
			super();
			this.userDao = userDao;
		}

		public void setUserDao(UserDao userDao) {
                this.userDao = userDao;
        }

        @Override
        public void add(User user) {
        	System.out.println("adding user");
            users.add(user);
        }

        @Override
        public List<User> list() {
        	System.out.println("listing users");
            return users;
        }

        @Override
        public void remove(User user) {
                
        }

        public User findUserByUsername(String username){
                for(User user: users){
                        if(user.getUsername().equals(username)){
                                return user;
                        }
                }
                return null;
        }
        
        public User dbUser(){
                return userDao.dbUser();
        }
        
        public void setAnotherUserDao(UserDao anotherUserDao) {
        	System.out.println("Injected: " + anotherUserDao);
        }
}